define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_level_setting/index' + location.search,
                    add_url: 'user_level_setting/add',
                    edit_url: 'user_level_setting/edit',
                    select_equity_url: 'user_level_setting/select_equity',
                    del_url: 'user_level_setting/del',
                    multi_url: 'user_level_setting/multi',
                    import_url: 'user_level_setting/import',
                    table: 'user_level_setting',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'level', title: __('Level')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'level_price', title: __('Level_price'), operate:'BETWEEN'},
                        {field: 'invite_upgrade_num', title: __('Invite_upgrade_num')},
                        {field: 'award_score', title: __('Award_score')},
                        {field: 'mom', title: __('Mom')},
                        {field: 'freeze_score', title: __('Freeze_score')},
                        {field: 'freeze_day', title: __('Freeze_day')},
                        {field: 'unfreeze', title: __('Unfreeze'), searchList: {"1":__('Unfreeze 1'),"0":__('Unfreeze 0')}, formatter: Table.api.formatter.normal},
                        {field: 'buy_award_score', title: __('Buy_award_score'), operate:'BETWEEN'},
                        {field: 'buy_award_money', title: __('Buy_award_money'), operate:'BETWEEN'},
                        {field: 'upgrade_money', title: __('Upgrade_money'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('选择会员权益'),
                                    title: __('选择会员权益'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'user_level_setting/select_equity',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate,}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        select_equity:function (){
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});